package com.bsoft.exchange.controller.listofexpenses;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.bsoft.exchange.domain.DrugFrequencyDomain;
import com.bsoft.exchange.domain.ListDisposalrecordDomain;
import com.bsoft.exchange.domain.ListHistoryRecordDomain;
import com.bsoft.exchange.domain.ListOutpatientExpenses;
import com.bsoft.exchange.domain.ListPatientDomain;
import com.bsoft.exchange.domain.OutpatientExpensesDetai;
import com.bsoft.exchange.pojo.AdmNumberPojo;
import com.bsoft.exchange.pojo.ListHistoryRecordPojo;
import com.bsoft.exchange.pojo.ListOutpatientExpensesPojo;
import com.bsoft.exchange.pojo.ListPatientPojo;
import com.bsoft.exchange.pojo.OrganizationIdPojo;
import com.bsoft.exchange.pojo.OutpatientExpensesDetaiPojo;
import com.bsoft.exchange.response.ResponseEntity;
import com.bsoft.exchange.response.ResponseStatus;
import com.bsoft.exchange.service.OutpatientService;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.Constant;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value="outpatient")
public class OutpatientController {

	@Autowired
	OutpatientService outpatientService;
	
	@ApiOperation(value = "获取门诊费用列表", 
			notes = "入参：hospitalCode：医院ID，医院系统身份标识 ; patientMedicalCardType ：诊疗卡类型; patientMedicalCardNumber ：诊疗卡号码; "
					+ "patientCode ：患者编号; patientIdentityCardType ：患者证件类型; patientIdentityCardNumber ：证件号码 ; "
					+ "startDate ：开始日期(yyyy-MM-dd); endDate ：截止日期(yyyy-MM-dd) ; pageNo ：页码; pageSize ：每页条数")
	@ResponseBody
	@RequestMapping(value = "/listOutpatientExpenses",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<Object> listOutpatientExpenses(@RequestBody ListOutpatientExpensesPojo listOutpatientExpensesPojo) {
		BaseResponse<List<ListOutpatientExpenses>> list = null;
		ResponseEntity<Object> entry = new ResponseEntity<>();

		try {
			list = outpatientService.listOutpatientExpenses(listOutpatientExpensesPojo);
		} catch (Exception e) {
			e.printStackTrace();
			entry.setCode(ResponseStatus.ERROR_CODE);
			entry.setMessage("处理失败");
		}
		
		entry.setData(list.getData());
		entry.setMessage(list.getMessage());
		if ("1".equals(list.getCode().toString())) {
			entry.setCode(ResponseStatus.SUCCESS_CODE);
		} else {
			entry.setCode(ResponseStatus.ERROR_CODE);
		}
		
		return entry;
	}
	
	
	@ApiOperation(value = "获取门诊费用详情", 
			notes = "入参：hospitalCode：医院ID，医院系统身份标识 ; patientCode ：医院挂号流水号;invoiceNumber:发票号码 ")
	@ResponseBody
	@RequestMapping(value = "/outpatientExpensesDetai",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<Object> outpatientExpensesDetai(@RequestBody OutpatientExpensesDetaiPojo outpatientExpensesDetaiPojo) {
		OutpatientExpensesDetai outpatientExpensesDetai = null;
		ResponseEntity<Object> entry = new ResponseEntity<>();

		try {
			outpatientExpensesDetai = outpatientService.outpatientExpensesDetai(outpatientExpensesDetaiPojo);
		} catch (Exception e) {
			e.printStackTrace();
			entry.setCode(ResponseStatus.ERROR_CODE);
			entry.setMessage("处理失败");
		}
		entry.setData(outpatientExpensesDetai);
		
		return entry;
	}
	
	@ApiOperation(value = "获取处置记录")
	@RequestMapping(value = "/listDisposalrecord",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<ListDisposalrecordDomain>> listDisposalrecord(@RequestBody AdmNumberPojo admNumberPojo)  {
		ResponseEntity<List<ListDisposalrecordDomain>> entity=new ResponseEntity();
		try{
			BaseResponse<List<ListDisposalrecordDomain>> returnMessage = outpatientService.listDisposalrecord(admNumberPojo);
		
			entity.setCode(returnMessage.getCode());
	    	entity.setMessage(returnMessage.getMessage());
			entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	@ApiOperation(value = "获取历史就诊记录")
	@RequestMapping(value = "/listHistoryRecord",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<List<ListHistoryRecordDomain>> listHistoryRecord(@RequestBody ListHistoryRecordPojo listHistoryRecordPojo)  {
		ResponseEntity<List<ListHistoryRecordDomain>> entity=new ResponseEntity();
		try{
			BaseResponse<List<ListHistoryRecordDomain>> returnMessage = outpatientService.listHistoryRecord(listHistoryRecordPojo);
		
			entity.setCode(returnMessage.getCode());
	    	entity.setMessage(returnMessage.getMessage());
			entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
	@ApiOperation(value = "获取门诊患者列表")
	@RequestMapping(value = "/listPatient",method = RequestMethod.POST,produces = "application/json")
	public ResponseEntity<ListPatientDomain> listPatient(@RequestBody ListPatientPojo listPatientPojo)  {
		ResponseEntity<ListPatientDomain> entity=new ResponseEntity();
		try{
			BaseResponse<ListPatientDomain> returnMessage = outpatientService.listPatient(listPatientPojo);
		
			entity.setCode(returnMessage.getCode());
	    	entity.setMessage(returnMessage.getMessage());
			entity.setData(returnMessage.getData());
		
		}catch(Exception e){
			entity.setCode(Constant.errorTag);
			entity.setMessage(e.getMessage()); 
		}

		return entity;

	}
	
}
